package com.toggery.POS.service;

import com.toggery.POS.entity.Clothing;
import com.toggery.POS.entity.ClothingRecord;
import com.toggery.POS.entity.Test;
import com.toggery.POS.dao.ClothingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClothingService {
    @Autowired
    ClothingMapper mapper ;

    public List<ClothingRecord> findAll(){
        return  mapper.queryForList();
    }
    public boolean save(Clothing clothing){
        if(mapper.selectByPrimaryKey(clothing.getId())==null){
            mapper.insert(clothing);
            return true;
        }else {
            return false;
        }

    }
    public boolean updateClothing(Clothing clothing){
        if(mapper.updateByPrimaryKey(clothing)>0){
            return true;
        }else {
            return false;
        }
    }
    public boolean deleteByid(int id){
        if(mapper.deleteByPrimaryKey(id)>0){
            return true;
        }else {
            return false;
        }
    }
    public Clothing findById(int id){
        return mapper.selectByPrimaryKey(id);
    }
//    精确查询
    public Clothing findByName(String name){
        return mapper.findByName(name);
    }
//    模糊查询
    public List<Clothing> findLikeName(String name){
        //加上通配符
        name = "%"+name+"%";
        return mapper.findLikeName(name);
    }

    public List<Clothing> findAllWithin() {
        return mapper.findAll();
    }
}
